package com.ymatou.iapi.livebuyer.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.SubscribeBean;
import com.ymatou.iapi.livebuyer.parameter.UnSubscribeBean;
import com.ymatou.iapi.livebuyer.service.SubscribeCall;
import com.ymatou.iapi.livebuyer.service.UnSubscribeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*取消订阅直播
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnSubscribe{
	private static UnSubscribeBean unsubscribeBean;
	private static UnSubscribeCall unsubscribeCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消订阅直播");
	}

	@Before
	public void caseUp() {
		unsubscribeBean=new UnSubscribeBean();
		unsubscribeCall=new UnSubscribeCall();
	
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(unsubscribeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_Subscribe_001() {
		Logger.start(true,"取消直播订阅，成功");
		try {
			//创建直播订阅
			SubscribeBean subscribeBean = new SubscribeBean();
			SubscribeCall subscribeCall = new SubscribeCall();
			
			int liveid=new LiveRoomWapper().selectLastLiveRoom().getId();
			int  userId=4085;	
			subscribeBean.setLiveId(liveid);
			subscribeBean.setUserId(userId);
			subscribeCall.setData(subscribeBean);
			subscribeCall.callService();			
			Logger.verifyEquals("200", subscribeCall.getString("code"), "判断code");			
			Map m1=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(1, Integer.parseInt(m1.get("Status").toString()),"验证Status");	
			//取消直播订阅
			unsubscribeBean.setLiveId(liveid);
			unsubscribeBean.setUserId(userId);
			unsubscribeCall.setData(unsubscribeBean);
			unsubscribeCall.callService();			
			Logger.verifyEquals("200", unsubscribeCall.getString("code"), "判断code");			
			Map m2=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(0, Integer.parseInt(m2.get("Status").toString()),"验证Status");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}